package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsCommentMapper;
import com.qf.pojo.DtsComment;
import com.qf.service.DtsAdminCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DtsAdminCommentServiceImpl implements DtsAdminCommentService {
    @Autowired
    DtsCommentMapper commentMapper;

    @Override
    public IPage<DtsComment> queryPage(Integer page, Integer limit, String sort, String order, Integer goodsId, Integer userId, List<Integer> brandIds) {
        IPage<DtsComment> ipage = new Page<>(page, limit);

        QueryWrapper<DtsComment> qw = new QueryWrapper<>();
        if(goodsId != null){
            qw.eq("c.value_id", goodsId );
        }
        if(userId != null){
            qw.eq("c.user_id", userId );
        }
        if(brandIds != null &&  brandIds.size() > 0) {
            qw.in("g.brand_id", brandIds);
        }
        qw.eq("c.deleted",0);
        ipage = commentMapper.selectCommentPage(ipage, qw);
        return ipage;
    }

    @Override
    public void delete(DtsComment comment) {
        comment.setDeleted(true);
        commentMapper.updateById(comment);
    }
}
